package crm;

import java.util.Scanner;
/**
 * 控制台文件，处理整个操作的逻辑
 * @author ZHUAN4
 *
 */
public class Consolo {
	  static DataHand dh=new DataHand();
      static CommandHandle cd=new CommandHandle();
      static String command="";
      static String commandKind="";
//      static String[] strCommand={};
	public static void main(String[] args) throws Exception {
	dh.initCRM();
		/**
		 * 初始界面
		 */
		System.out.println("····················································");
		System.out.println("·                                                  ·");
		System.out.println("·            Wlecome to oocl CRM!                  ·");
		System.out.println("·                                                  ·");
		System.out.println("·                input 'HELP' to see help document!·");
		System.out.println("····················································");
		System.out.println();
		Scanner in=new Scanner(System.in);
		do{
			System.out.println("·············Please input your command··············");
			command="";
		    commandKind="";
		    command=in.nextLine();
		    commandKind=cd.commandHandle(command);
		    String[] strCommand=command.split(" ");
		    switch(commandKind){		    
		    case "L"      : dh.lookCRM(); break;
		    case "L id"   : dh.lookByIdCRM(StringHandle.getId(strCommand[2]));break;
		    case "L name" : dh.lookByNameCRM(StringHandle.getName(strCommand[2]));break;
		    case "A"      : dh.addCRM(StringHandle.getCustomer(strCommand[1]));break;
		    case "D id"   : dh.deleteCRM(StringHandle.getId(strCommand[1])); break;
		    case "U id"   : dh.updateCRM(StringHandle.getId(strCommand[1]), StringHandle.getCustomer(strCommand[2]));break;
		    case "O id"   : dh.sortByIdCRM();dh.lookCRM();break;
		    case "O name" : dh.sortByNameCRM(); dh.lookCRM();break;
		    case "H"      :  break;
		    case "Q"      :  break;
		    case "None"   :System.out.println("The command you input is error!");break;
		    default       :System.out.println("The command you input is error!");break;
		    }
		    System.out.println();
		}while(true);
	}

}
